package edu.stu.software.family.people.mapper.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;

import edu.stu.software.family.jdbc.JDBCUtil;
import edu.stu.software.family.people.domain.People;
import edu.stu.software.family.people.mapper.PeopleMapper;

/**
 * 
 * @author cao_xian_ke
 *
 */
public class PeopleMapperImpl implements PeopleMapper {
    private static Connection conn = null;
    private static PreparedStatement pstmt = null;
    @Override
    public int add(People people){
        try {
            conn = JDBCUtil.getConnection();
            String sql = "insert into people(name,age,sex,telephone) values(?,?,?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,people.getName());
            pstmt.setInt(2,people.getAge());
            pstmt.setString(3,people.getSex());
            pstmt.setString(4,people.getTelephone());
            int update = pstmt.executeUpdate();
            return update;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }finally {
            try {
                JDBCUtil.Close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
